/*
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2022-04-20 16:30:58
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-04-21 09:35:50
 * @FilePath: \code\cwp-front\pc-collaboration\src\store\modules\summary\supervise-set.js
 * @Description: 督办设置
 */
import { defineStore } from 'pinia';
import pinia from '@/store';

//关键数据初始值
export const INIT_DATA = {
    //督办期限
    superviseAwakeDate: 0,
    //督办主题
    superviseTitle: '',
    //督办人员id
    supervisorIds: '',
    //督办人员名字
    supervisorNames: '',
    //是否只读
    readOnly:false,
};
export const useSuperviseSetStore = defineStore('superviseSet', {
    state: () => ({
        originData: INIT_DATA,
        //督办id，新建时候不用上传
        detailId: '',
        //是否修改过督办。修改过后台要重新推送消息
        isModifySupervise: false,
        ...INIT_DATA,
    }),
    actions: {
        /**
         * @description:设置督办数据
         * @param {Object}data 传入的数据
         * @param {Boolean}isInitial 是否是初始化。初始化保存的值用于对比是否修改
         * @return {*}
         */
        setSuperviseData(data, isInitial = false) {
            //没有就不设置
            if (!data) return;
            //如果是页面初始化，就设置初始值
            if (isInitial) {
                this.originData = data;
            }
            const {
                detailId = '',
                superviseAwakeDate = 0,
                superviseTitle = '',
                supervisorIds = '',
                supervisorNames = '',
                isModifySupervise = false,
                readOnly = false,
            } = data;

            //有id就不改。（属于编辑）
            if (!this.detailId) {
                this.detailId = detailId;
            }
            this.superviseAwakeDate = superviseAwakeDate;
            this.superviseTitle = superviseTitle;
            this.supervisorIds = supervisorIds;
            this.supervisorNames = supervisorNames;
            this.isModifySupervise = isModifySupervise;
            this.readOnly = readOnly;
        },
    },
});

//在vue上下文之外使用
export function useSuperviseSetWithOut() {
    return useSuperviseSetStore(pinia);
}
